<?PHP 
defined('_ACCESS') or die( 'Direct Access to this location is not allowed.' );
defined('_LOCATION') or die( 'Direct Access to this location is not allowed.' );

global $db, $access, $item, $id, $option, $_live_site, $_absolute_path;

global $start, $inpage, $filter_author;

global $Prod_name, $Filial_name;

if ($db->getSetting('access') and $db->getSetting('Prod_id'))
{	
	$Prod_id = $db->getSetting('Prod_id');
	
	
	$Lang = $db->getSetting('Lang');
	$User_id = $db->getSetting('User_id');	
	
	$res=$db->query("SELECT $Lang AS trans
				FROM Translation INNER JOIN ProdList
										ON Translation.id = ProdList.translation_link
				WHERE     (ProdList.id = $Prod_id) LIMIT 0, 1");
	$cur_prod = $db->fetchObject($res);
	$Prod_name = $cur_prod->trans;				
	//				
	$res=$db->query("SELECT $Lang AS trans, ParamList.has_fixed_values,  ProdAndParam.prod_link, ProdAndParam.param_link, ParamList.name, ProdAndParam.order
					FROM Translation INNER JOIN  ParamList 
											ON Translation.id = ParamList.translation_link 
									INNER JOIN ProdAndParam 
											ON ParamList.id = ProdAndParam.param_link
					WHERE     (ProdAndParam.prod_link = $Prod_id) 
					ORDER BY ProdAndParam.order");
	
	
	
	
	
?>
<div id="main">		
	<div class="prod_name"><?php echo $Prod_name;?></div>
	<form method="post" action="index.php" name="loginForm" id="loginForm" enctype="multipart/form-data">
	
<?php
$params = array();
$types = array();


	while($cur_param = $db->fetchObject($res))
	{	
		$params[$cur_param->param_link] = $cur_param;		
	}
	
	/*foreach($params as $param_key => $param_value)
	{
?><?php
	}*/
?><?php


	
	$res=$db->query("SELECT $Lang AS trans, TypeList.id
					FROM         Translation INNER JOIN
                	    	  		TypeList INNER JOIN
                    	  			ProdAndType ON TypeList.id = ProdAndType.prodtype_link ON Translation.id = TypeList.translation_link
				WHERE     (ProdAndType.prod_link = $Prod_id)");	
	
	while($cur_type = $db->fetchObject($res))
	{	
		$types[$cur_type->id] = $cur_type;		
	}
	
	foreach($types as $type_key => $type_value)
	{
?>	
		<div class="container">
			<div class="breakline"></div>		
			
			<div class="float">
				<div class="capt"><?php echo WWW_TYPE;?></div>
				<?php echo $type_value->trans;?>
			</div>			
<?php
		foreach($params as $param_key => $param_value)
		{				
			$cur_val = null;
			$res=$db->query("SELECT Data.val, Data.id
							FROM TypeList INNER JOIN
									Data INNER JOIN
			                      ProdList ON Data.prod_link = ProdList.id INNER JOIN
			                      ParamList ON Data.param_link = ParamList.id ON TypeList.id = Data.prod_type_link 
				WHERE     (Data.user_link = $User_id) 
							AND (Data.prod_link = $Prod_id) 
							AND (Data.prod_type_link = $type_key) 
							AND (Data.modif_date like '".flipDate($db->getSetting('ViewDate'), '.')."%') 
							AND (Data.param_link = $param_key) LIMIT 1");				
			
			if ($cur_val = $db->fetchObject($res)) 
			{		
				$curv_val = $cur_val->val;
				$curv_id = $cur_val->id;
			}
			else 
			{
				$curv_val = '';
				$curv_id = '-1';
			}
			
			
?>
			<div class="float">
				<div class="capt"><?php echo $param_value->trans;?><?php $param_key;?></div>
				
				
				<div class="capt"><?php echo ($param_value->has_fixed_values);?><?php echo $param_key;?></div>
				
				
				
				
				
				
				
				
					<INPUT class="input_data" size="5" name="data[<?php echo "$type_key";?>][<?php echo "$param_key";?>]" type="text" value="<?php echo $curv_val;?>">				
					<INPUT name="data_id[<?php echo "$type_key";?>][<?php echo "$param_key";?>]"  type="hidden" value="<?php echo $curv_id;?>">
			</div>					
				
<?php		
		}
?>
					
					<div class="breakline"></div>
		</div>
<?php
	}
?>
				
			
			
			
		























			


			
			
			<div class="saveButton">
				<input type="submit" class="inputbox" value="<?php echo WWW_SAVE;?>">
			</div>					
			</form>			
<?php	
}
?>				

</div>
<?php
//$db->Deb_PRNT();
?>				